package com.fly.core.utils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.Container;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DockerUtils
{
    public static String host(DockerClient dockerClient)
    {
        return dockerClient.getHost();
    }
    
    public static List<Container> containers(DockerClient dockerClient)
    {
        return listContainers(dockerClient).stream().collect(Collectors.toList());
    }
    
    /**
     * 运行容器列表
     * 
     * @param dockerClient
     * @return
     * @see [类、类#方法、类#成员]
     */
    private static List<Container> listContainers(DockerClient dockerClient)
    {
        try
        {
            return dockerClient.listContainers();
        }
        catch (DockerException | InterruptedException e)
        {
            log.error(e.getMessage());
        }
        return Collections.emptyList();
    }
}
